package com.jinzhi.api.controller.aunt;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.jinzhi.api.service.AuntHomeService;
import com.jinzhi.common.utils.Result;
import com.jinzhi.jzapi.domain.UserDO;
import com.jinzhi.jzweb.domain.JazInterviewDO;
import com.jinzhi.jzweb.domain.JazMessageDO;
import com.jinzhi.jzweb.domain.MessageplatfromDO;
import com.jinzhi.jzweb.service.JazMessageService;
import com.jinzhi.jzweb.service.MessageplatfromService;
import com.jinzhi.sms.support.SmsManager;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: mcf
 * @CreateTime: 2024/05/16
 * @Description: 消息管理 Controller
 */
@Controller
@RequestMapping("/api/auntMessage")
@Api(value = "阿姨端消息管理", tags = "阿姨端消息管理")
public class AuntMessageController {

    private final JazMessageService jazMessageService;

    private final AuntHomeService auntHomeService;

    @Autowired
    private SmsManager smsSerevice;

    public AuntMessageController(JazMessageService jazMessageService,AuntHomeService auntHomeService){
        this.jazMessageService = jazMessageService;
        this.auntHomeService = auntHomeService;

    }

    @ApiOperation(value = "消息查询接口（轮询）", notes = "消息查询接口（轮询）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "messageType", value = "消息类型（1.系统消息、2.订单消息）", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "receiverId", value = "接收者id(即用户id)", required = true, dataType = "Long"),
    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功",response = JazMessageDO.class),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @GetMapping("/messageList")
    public Result<?> messageList(Integer messageType,Long receiverId){

        return Result.ok(jazMessageService.messageList(messageType,receiverId));
    }

    @ApiOperation(value = "首次查询消息列表 （获取数据库）", notes = "首次查询消息列表 （获取数据库）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "messageType", value = "消息类型（1.系统消息、2.订单消息）", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "receiverId", value = "接收者id(即用户id)", required = true, dataType = "Long"),
    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功",response = JazMessageDO.class),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @GetMapping("/getMessage")
    public Result<?> getMessage(Integer messageType,Long receiverId){

        return Result.ok(jazMessageService.getMessage(messageType,receiverId));
    }


    @ApiOperation(value = "发送消息", notes = "发送消息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "messageType", value = "消息类型（1.系统消息、2.订单消息）", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "senderId", value = "发送者id", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "receiverId", value = "接收者id", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "objectId", value = "媒介id", required = true, dataType = "Long"),
    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功",response = JazMessageDO.class),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @PostMapping("/senMessage")
    public Result<?> senMessage(JazMessageDO jazMessageDO){
        jazMessageService.senMessage(jazMessageDO);
        return Result.ok();
    }


    @ApiOperation(value = "修改阅读状态", notes = "修改阅读状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "messageType", value = "消息类型（1.系统消息、2.订单消息）", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "receiverId", value = "接收者id", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "Long"),
    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功",response = JazMessageDO.class),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @PostMapping("/changeRead")
    public Result<?> changeRead(JazMessageDO jazMessageDO){
        jazMessageService.changeRead(jazMessageDO);

        return Result.ok();
    }


    @ApiOperation(value = "用户端修改阅读状态", notes = "用户端修改阅读状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "messageId", value = "消息表id", required = false, dataType = "Long"),
    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功",response = JazMessageDO.class),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @PostMapping("/changeUserRead")
    public Result<?> changeUserRead(Long messageId){
        jazMessageService.changeUserRead(messageId);
        return Result.ok();
    }


    @ApiOperation(value = "查询消息未读数量", notes = "查询消息未读数量")
    @ApiImplicitParams({
    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功",response = JazMessageDO.class),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @GetMapping("/changeRead")
    public Result<?> getMessageNum(){

        return Result.ok(jazMessageService.getMessageNum());
    }


    /**
     * 订单消息详情
     * @return
     */
    @ApiOperation(value = "订单消息详情", notes = "订单消息详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "demandId", value = "需求id", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "messageId", value = "消息id", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "interviewId", value = "邀约id", required = true, dataType = "Long"),
    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功",response = JazMessageDO.class),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @GetMapping("/messageType2Detail")
    public Result<?> messageType2Detail(Long demandId,Long interviewId, Long messageId){


        return Result.ok(jazMessageService.messageType2Detail(demandId,interviewId,messageId));
    }

    /**
     * 阿姨取消或者同意邀约
     * @return
     */
    @ApiOperation(value = "阿姨取消或者同意邀约", notes = "阿姨取消或者同意邀约")
    @ApiImplicitParams({
    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功",response = JazInterviewDO.class),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @PostMapping("/cancelInterview")
    public Result<?> cancelInterview(@RequestBody JazInterviewDO jazInterviewDO){
        auntHomeService.cancelInterview(jazInterviewDO);

        return Result.ok();
    }


    @ApiOperation(value = "发送短信test", notes = "发送短信test")
    @ApiImplicitParams({
    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功",response = JazMessageDO.class),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @GetMapping("/test")
    public Result<?> test(){
        Map templateParam = new HashMap();
        templateParam.put("name","丁武乐");
        templateParam.put("time","2024-06-18");
        smsSerevice.send1("16721560740", "SMS_468395772", "金职到家", templateParam);
        return Result.ok();
    }


}
